<?php
namespace app\wx\controller;
use module\InsurerApi;
use library\Validator;
use library\AliOss;
use library\Alisms;
use OSS\OssClient;
use module\UploadApi;
use think\Db;
class Index extends CommonController
{
    protected $_require_login = true;
    public function index()
    {
        $user_info= Db::table('user_info')->where('ui_id',$this->uid)->find();
        $role=Db::table('index_role')->where('role_id',  $user_info['role_id'])->find();
        $user_info['role_name'] =$role['role_name'];
      //  dump($user_info);exit;
        if($user_info['role_id'] == 4){
            $this->redirect('SaleMan/index?type=1');
        }
        return $this->fetch('index/index',['userInfo'=>$user_info]);

    }

    /**
     * 获取省
     */
    public function getOmit(){
        $whereprovince['top_parentid'] = 0;
        $listprovince = Db::table('egion')->field('region_id,region_name')->where($whereprovince)->select();
        return $this->response->api(['province_list'=>$listprovince]);
    }
    /**
     * 市
     */
    public function getCitys(){
        list($region_id) = Validator::make($this->request->request(), [
            'region_id' => 'required',
        ]);
        $where['top_parentid'] =$region_id;
        $where['level'] = 2;
        $list = Db::table('egion')->field('region_id,region_name')->where($where)->select();
        return $this->response->api(['citys_list'=>$list]);
    }
    /**
     *获取地级县
     */
    public function getDistrict(){
        list($region_id) = Validator::make($this->request->request(), [
            'region_id' => 'required',
        ]);
        $where['parent_id'] = $region_id;
        $where['level'] = 3;
        $list = Db::table('egion')->field('region_id,region_name')->where($where)->select();
        return $this->response->api(['district_list'=>$list]);
    }
    /**
     *获取保险种类列表
     */
    public function getInsuranceType(){
        $list = Db::table('insurance_type')->field('it_id,it_name')->where('deleted',0)->select();
        return $this->response->api(['type_list'=>$list]);
    }
    /**
     *获取代录人类型
     */
    public function recorderType(){
        $list = Db::table('recorder_type')->select();
        return $this->response->api(['type_list'=>$list]);
    }
    /**
     *获取商品类型
     */
    public function goodsType(){
        $list = Db::table('goods_type')->field('gt_id,gt_name')->where('deleted',0)->select();
        return $this->response->api(['type_list'=>$list]);
    }
    /**
     *新手引导
     */
   public  function  newHand(){
       return $this->fetch('index/help');
   }
    /**
     *设置
     */
    public  function  setting(){
        return $this->fetch('index/setting');
    }
    /**
     *关于我们
     */
    public  function  aboutUs(){
        return $this->fetch('index/about_us');
    }
    /**
     *关于我们
     */
    public  function  serveItems(){
        return $this->fetch('index/serve_items');
    }
    /**
     *新手引导详情
     */
    public  function  newHandInfo1(){
        return $this->fetch('index/help_detail');
    }
    /**
     *退出
     */
    public  function  logout(){
        session('user_info',null);
        //$this->redirect('wx/Login/login');
    }

    /*************************************************************************/
    //查看模板
    public function  test1(){
        return $this->fetch('index/step01');
    }
    public function  test2(){
        return $this->fetch('index/step02');
    }
    public function  test3(){
        return $this->fetch('index/step03');
    }
    public function  test4(){
        return $this->fetch('index/step04');
    }
    public function  test5(){
        return $this->fetch('index/step05');
    }
    public function  test6(){
        return $this->fetch('index/step06');
    }


    /*******************************************************************/
    public function check_msg()
    {
        $id = $this->uid;
        $where = [
            'ui_id'=>$id,
            'mn_status'=>1
        ];
        $res = Db::table('message_notice')->where($where)->count();
        return json(['data'=>$res,'code'=>200]);
    }

}
